package conceptmaniax.hotelapp.adapters;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import conceptmaniax.hotelapp.activities.R;
import conceptmaniax.hotelapp.pojos.Request;

public class RequestListAdapter extends BaseAdapter implements OnClickListener {
    
	private Context context;
    private List<Request> requestList;

	public List<Request> getRequestList() {
		return requestList;
	}

	public void setRequestList(List<Request> requestList) {
		this.requestList = requestList;
	}

	public RequestListAdapter() {
    	super();
    }
    
    public RequestListAdapter(final Context context, final List<Request> requestList) {
    	super();
    	this.context = context;
        this.requestList = requestList;
    }

    public int getCount() {
        return requestList.size();
    }

    public Object getItem(final int position) {
        return requestList.get(position);
    }

    public long getItemId(final int position) {
        return position;
    }

    public View getView(final int position, View convertView, final ViewGroup viewGroup) {
        final Request item = requestList.get(position);
        
        if (convertView == null) {
            final LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.request_row, null);
        }
       
		final TextView type = (TextView) convertView.findViewById(R.id.service_type);
		final TextView inserted = (TextView) convertView.findViewById(R.id.service_inserted);
		final TextView details = (TextView) convertView.findViewById(R.id.service_details);
		final TextView requested = (TextView) convertView.findViewById(R.id.service_requested);
        
		type.setText(item.getMenu_name());
		inserted.setText(item.getInserted_time());
		details.setText("Dear Mr User\nWe have received your request: "+item.getServices()+"\nNotes: "+item.getNotes());
		requested.setText("REQUESTED SERVICE DATE: "+item.getRequested_time());
        return convertView;
    }

    @Override
    public void onClick(final View view) {
        final Request entry = (Request) view.getTag();
        requestList.remove(entry);
        notifyDataSetChanged();
    }
}
